FROM golang:alpine AS builder

LABEL stage=gobuilder

ENV GO111MODULE on
ENV CGO_ENABLED 0
ENV GOOS linux
ENV GOPROXY https://goproxy.cn,direct
#ENV GOPRIVATE *.supremind.info

WORKDIR /go/cache
ADD go.mod .
ADD go.sum .
RUN go mod download

WORKDIR /go/src
COPY . .

# 去掉了调试信息 -ldflags="-s -w" 以减小镜像尺寸
RUN go build -ldflags="-s -w" -o /app/hello ./main.go

FROM alpine

# 安装了 ca-certificates，这样使用 TLS证书就没问题了
RUN apk update --no-cache && apk add --no-cache ca-certificates tzdata

ENV TZ Asia/Shanghai

WORKDIR /app

COPY --from=builder /app/hello /app/hello

CMD ["./hello"]